﻿namespace VIT.BusinessLogicLayer
{
    using System.Collections.Generic;
    using System.Linq;

    using VIT.DataAccessLayer;
    using VIT.DataTransferObjects.Presentation;

    public class ProvinceBLL : BLLBase
    {
        private readonly IProvinceDAL _provinceDAL;

        #region Constructor
        public ProvinceBLL(string connectionString = "")
            : base(connectionString)
        {
            this._provinceDAL = new ProvinceDAL(this.DatabaseFactory);
        }
        #endregion

        #region Province
        public List<ProvinceDto> GetAll(int Skip = 0, int Take = 0)
        {
            var dtoQuery = this._provinceDAL.GetAllIncludeItem()
                .Where(e => e.Item.IsPublished)
                .OrderBy(e => e.Item.Orders)
                .Select(entity => new ProvinceDto
                {
                    Id = entity.Id,
                    Name = entity.Name,
                    Code = entity.Code
                });

            if (Skip > 0) dtoQuery = dtoQuery.Skip(Skip);
            if (Take > 0) dtoQuery = dtoQuery.Take(Take);

            var result = dtoQuery.ToList();

            return result;
        }
        #endregion
    }
}
